package com.lexian.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.lexian.entity.Recaddr;
import com.lexian.service.RecaddrService;
import com.lexian.utils.CommonResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 * 收货地址 前端控制器
 * </p>
 *
 * @author testjava
 * @since 2021-01-14
 */
@RestController
@RequestMapping("/recaddr")
public class RecaddrController {
    @Autowired
    private RecaddrService recaddrService;
    /**
     * 修改地址
     * @param recaddr 地址
     * @return
     */
   @GetMapping("modifyRecaddr")
    public CommonResponse modifyRecaddr(Recaddr recaddr){
       recaddrService.modifyRecaddr(recaddr);
        return CommonResponse.ok();
    }

    /**
     * 添加地址
     * @param recaddr
     * @return
     */
    @GetMapping("addRecaddr")
    public CommonResponse addRecaddr(Recaddr recaddr){
        recaddrService.addRecaddr(recaddr);
        return CommonResponse.ok();
    }

    /**
     * 查询用户地址
     * @param cusId
     * @return
     */
    @GetMapping("getAllRecaddr/{cusId}")
    public CommonResponse getAllRecaddr(@PathVariable Long cusId){
        return CommonResponse.ok().data("list",recaddrService.getAllRecaddr(cusId));
    }

    /**
     * 删除地址
     * @param recaddrId
     * @param cusId
     * @return
     */
    @GetMapping("deleteRecaddrByrecaddrId/{recaddrId}")
    public CommonResponse deleteRecaddrByrecaddrId(@PathVariable Long recaddrId){
        recaddrService.deleteRecaddrByrecaddrId(recaddrId);
        return CommonResponse.ok();
    }

    /**
     * 使用指定地址
     * @param recaddrId
     * @return
     */
    @GetMapping("getRecaddrByrecaddrId/{recaddrId}")
    public CommonResponse getRecaddrByrecaddrId(@PathVariable Long recaddrId){
        return CommonResponse.ok().data("recaddr",recaddrService.getRecaddrByrecaddrId(recaddrId));
    }
}

